<script type="text/javascript">
	var i = 0, getCodeValueRow = function() {
		return {
			id:'',
			orderNo : ++i,
			value : "id",
			name : "ID"
		};
	};
	function addCodeValue() {
		dictionary_codevaluelist.datagrid("appendRow", getCodeValueRow());
	}
	function removeCodeValue() {
		var rows = dictionary_codevaluelist.datagrid('getChecked');
		printLog(rows);
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除记录吗?',function(r){
	            if (r){
	            	for (var i = rows.length - 1; i >= 0; i--) {
	            		printLog(rows[i]);
	            		var index = dictionary_codevaluelist.datagrid('getRowIndex', rows[i]);
	            		dictionary_codevaluelist.datagrid('deleteRow', index);
	            	}
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
    }
	
	function saveDictionaryCodeValueInfo() {
		printLog('------------')
		var rows = dictionary_codevaluelist.datagrid('getRows');
    	var dictionaryInfo = [{
    		id:$('#dictionaryId').val(),
    		key:$('#dictionaryKey').val(),
    		name:$('#dictionaryName').val(),
			codeValues:rows
    	}];
    	printLog(dictionaryInfo);
    	$.post("dictionaryCode.do?saveDictionaryCodeValues", {data:JSON.stringify(dictionaryInfo)}, function(result) {
               if(result.success){
            	  showMsg('保存成功.');
            	  reloadDictionary();
               }else {
            	   showMsg('保存失败.');
               }
       }, "JSON");
	}
</script>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region: 'north', border:false" >
		<table cellpadding="5">
			<input id="dictionaryId" name="id" type="hidden" value="${(dictionaryCodeItem.id)!}" />
			<tr>
				<td>字典key:</td>
				<td>
					<input id="dictionaryKey" name="key"  class="easyui-validatebox" data-options="required: true" value="${(dictionaryCodeItem.key)!}"/>
				</td>
				<td>名称:</td>
				<td>
					<input id="dictionaryName" name="name"  class="easyui-validatebox" data-options="required: true" value="${(dictionaryCodeItem.name)!}"/>
				</td>
			</tr>
		</table>
	</div>
	<div data-options="region:'center',border:false">
			<@eu.datagrid id="dictionary_codevaluelist" title="字典值" toolbar="#codeValueList_toolbar" idField="id" autoEditing="true" singleEditing="true" extEditing="true"
			 url="codeValue.do?loadByCondition&dictionaryId=${(dictionaryCodeItem.id)!}" rownumbers="false" pagination="false"
			 item="com.xdtech.sys.vo.CodeValueItem"/>
			 
		<div id="codeValueList_toolbar">
			<@eu.linkbutton showName="新增" shiro="sys:dictionaryCodeValue:add" iconCls="icon-add" onclick="addCodeValue()"/>
			<@eu.linkbutton showName="删除" shiro="sys:dictionaryCodeValue:delete" iconCls="icon-remove" onclick="removeCodeValue()"/>
		</div>
	</div>
</div>
